package com.zwk.oss.controller;

import com.zwk.base.entity.CommonResult;
import com.zwk.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zwk
 * @create 2022/8/21 16:36
 */
@RestController
@CrossOrigin
@RequestMapping("/oss")
public class OssController {

    @Autowired
    private OssService ossService;

    @PostMapping("/upload")
    public CommonResult upload(MultipartFile multipartFile){

        // 返回文件在oss服务器中的访问路径
        String url = ossService.uploadAvatar(multipartFile);

        return CommonResult.ok().data("url", url);
    }

}
